# $Id: PKGBUILD 82156 2013-01-09 16:56:38Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Marcin Karpezo <sirmacik at gmail dot com>

pkgbase=scala
pkgname=(scala scala-docs scala-sources)
pkgver=2.10.0
pkgrel=1
_distdate=20121205-235900
_distsha=18481cef9b
pkgdesc="A Java-interoperable language with object-oriented and functional features"
arch=('any')
url="http://www.scala-lang.org"
license=('custom')
depends=('java-runtime=6')
makedepends=('apache-ant' 'git')
source=(http://www.scala-lang.org/downloads/distrib/files/scala-sources-$pkgver.tgz
	http://www.scala-lang.org/downloads/distrib/files/scala-docs-$pkgver.txz)
md5sums=('4f9e70bb90bab9f3d4565ae9f439322b'
         '4c500dfb17786fa7b47f4083276b7155')

# workaround#1: build requires unicode
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# workaround#2: set nobody's homedir to /tmp in chroot if using devtools

build(){
    cd ${srcdir}/${pkgname}-${pkgver}-sources
    chmod 0755 tools/*
    echo -e "#!/bin/bash\necho ${_distdate}" >tools/get-scala-commit-date
    echo -e "#!/bin/bash\necho ${_distsha}" >tools/get-scala-commit-sha

    export ANT_OPTS="-Xms2500M -Xmx2500M -Xss8M -XX:MaxPermSize=1024M -XX:+UseParallelGC"

    ant docs
    ant dist.src
    ant dist-opt -Dbuild.release=true
}

package_scala()
{
  depends=('java-runtime')
  optdepends=('scala-docs'
	    'scala-sources')

    cd ${srcdir}/${pkgname}-${pkgver}-sources/dists/latest/
    install -d ${pkgdir}/usr/{bin,share} ${pkgdir}/usr/share/man/man1 ${pkgdir}/usr/share/scala/{bin,lib}
    cp -r {lib,misc} ${pkgdir}/usr/share/scala/
    cp -r man ${pkgdir}/usr/share/
    install -m 755 bin/{fsc,scala,scalac,scalap,scaladoc} ${pkgdir}/usr/share/scala/bin
    install -D -m0644 doc/LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
    ln -s ../share/scala/bin/fsc ${pkgdir}/usr/bin/fsc
    ln -s ../share/scala/bin/scala ${pkgdir}/usr/bin/scala
    ln -s ../share/scala/bin/scalac ${pkgdir}/usr/bin/scalac
    ln -s ../share/scala/bin/scalap ${pkgdir}/usr/bin/scalap
    ln -s ../share/scala/bin/scaladoc ${pkgdir}/usr/bin/scaladoc
}

package_scala-docs()
{
    replaces=('scala-doc' 'scala-devel-docs')
    pkgdesc="Scala documentation"
    depends=('scala')

    cd ${srcdir}
    mkdir -p $pkgdir/usr/share/doc/
    cp -r scala-docs-$pkgver $pkgdir/usr/share/doc/scala
}

package_scala-sources()
{
    replaces=('scala-src')
    pkgdesc="Scala sources"
    depends=('scala')

    cd ${srcdir}/scala-${pkgver}-sources/dists
    cd latest
    mkdir -p $pkgdir/usr/share/scala/
    cp -r src $pkgdir/usr/share/scala/src
}
